#include <REGX52.H>
 
void Delay(unsigned int xms)		
{
	unsigned char i, j;
	while(xms--)
	{
		i = 2;
		j = 199;
		do
		{
			while (--j);
		} while (--i);
	}
}
 
void Init0()
{
	EA=1;
	EX0=1;
	IT0=1;
}
 
unsigned char Key_Interrupt_Flag=0;
 
void Init0_Routine() interrupt 0
{
	Key_Interrupt_Flag=1;
}
	
void main()
{
	unsigned char Mode=0;
	Init0();
	while(1)
	{
		if(Key_Interrupt_Flag)
		{
			Key_Interrupt_Flag=0;
			Mode++;
			if(Mode>=3)
			{
				Mode=0;
			}
		}
		
		switch (Mode)
		{
			case 0:
				{P2=0xfe;}
				break;
			case 1:
				{P2=0xf0;Delay(300);P2=0X0F;Delay(300);}
				break;
			case 2:
				{P2=0XAA;Delay(300);P2=0x55;Delay(300);}
				break;
			default:
				break;
		}	
	}
}